//package com.guoranhao.web.util;
//
//import com.google.common.collect.Lists;
//import com.guoranhao.business.enums.ChannelInfoEnum;
//import com.guoranhao.business.enums.OrderAccessChannelEnum;
//import com.guoranhao.business.model.EcOrder;
//import com.guoranhao.business.model.EcOrderDetail;
//import com.guoranhao.business.param.EcOrderCommodityCommonParamter;
//import com.guoranhao.business.param.EcOrderCommodityParamter;
//import com.guoranhao.business.param.EcOrderParamter;
//import com.guoranhao.tool.enums.ZeroOrOneEnum;
//import com.guoranhao.tool.utils.EncryptUtil;
//import com.guoranhao.tool.utils.JsonUtil;
//import com.guoranhao.web.param.EcOrderCommonParameter;
//import com.guoranhao.web.vo.EcOrderCreateParameter;
//import com.guoranhao.web.vo.UserLoginBindingParameter;
//import net.sf.json.JSONObject;
//import org.apache.commons.lang.StringUtils;
//import org.apache.commons.lang.time.DateUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.util.CollectionUtils;
//
//import java.io.UnsupportedEncodingException;
//import java.math.BigDecimal;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * Description:生态链电商 订单辅助类
// * Copyright (c) Department of Research and Development/Beijing
// * All Rights Reserved.
// * @Version 1.0  2018-07-17 19:17.by 王利涛(wanglt@cloud-young.com) 创建
// */
//public class OrderObjectWebUtils {
//    private static final Logger logger= LoggerFactory.getLogger(OrderObjectWebUtils.class);
//
//    private static final String ORDER_SALT="!@#$%^&*()llbordercreate";
//    //订单提交待支付最小时间
//    private static final Integer minAwaitPaySeconds=1200;
//
//    /**
//     * @Description: 根据输入参数生成下单签名字符串
//     * @Version 1.0  2018-06-19  20:07  by  王利涛(wanglt@cloud-young.com) 创建
//     * @param   param 输入参数
//     * @return  返回签名字符串
//     */
//    public static String signForCreateEcOrder(EcOrderCommonParameter param){
//
//        List<EcOrderCommodityParamter> orderCommoditys = param.getOrderCommoditys();
//        StringBuilder sub = new StringBuilder();
//        //订单商品信息
//        orderCommoditys.sort(Comparator.comparing(EcOrderCommodityCommonParamter::getCommoditySkuId));
//        orderCommoditys.stream().forEach(orderCommodity -> {
//            sub.append(orderCommodity.toString()).append(";");
//        });
//        sub.deleteCharAt(sub.length() - 1).append("&");
//
//        if (sub.substring(sub.length() - 1).equals(";")) {
//            sub.deleteCharAt(sub.length() - 1).append("&");
//        }
//        //订单收货地址
//        sub.append(param.getReceiverAddressId());
//        sub.append("&").append(param.getOrderTotalAmount().setScale(2, BigDecimal.ROUND_HALF_UP)).append("&").append(param.getPayAmount().setScale(2, BigDecimal.ROUND_HALF_UP))
//               .append(param.getDiscountAmount().setScale(2, BigDecimal.ROUND_HALF_UP))
//               .append(param.getOrderDiscountAmount().setScale(2, BigDecimal.ROUND_HALF_UP))
//               .append(param.getCommodityDiscountAmount().setScale(2, BigDecimal.ROUND_HALF_UP))
//                .append(param.getPurchaseType());
//        return EncryptUtil.MD5(sub.toString(), ORDER_SALT);
//    }
//
//     /**
//      * @Description: 获取终端用户信息
//      * @Version 1.0  2018/8/31  9:56  by  王利涛(wanglt@cloud-young.com) 创建
//      * @param   user 用户实体
//      * @return
//      */
//    public static String getTerimalInfo(UserBaseInfo user){
//		TerminalInfo ti = new TerminalInfo();
//		OrderObjectUtils.copy(user, ti);
//		return JSONObject.fromObject(ti).toString();
//	}
//
//     /**
//      * @Description: 通过商品信息快照得到商品实体
//      * @Version 1.0  2018/8/31  9:57  by  王利涛(wanglt@cloud-young.com) 创建
//      * @param   skuVo 商品信息快照
//      * @return
//      */
//     public static ProductVo convertSnapshotToProduct(ShopCarInfoSnapshot skuVo,Integer accessChannel,Integer showIconType){
//         ProductVo pv = new ProductVo();
//         OrderObjectUtils.copy(skuVo, pv);
//         List<OrderCarImageVo> detailList= skuVo.getOrderCarImageVos();
//         if(org.apache.commons.collections.CollectionUtils.isEmpty(detailList)){
//             detailList= Lists.newArrayList();
//         }
//         Optional<OrderCarImageVo> optional=null;
//         if(OrderAccessChannelEnum.PC_WEB_MALL.getCode().equals(accessChannel)){
//             //PC web商城访问渠道
//             optional = detailList.stream().filter(
//                     detail->{
//                         return ShopCarTypeIconTypeEnums.ICON_WEB.getCode().equals(detail.getChannelType())
//                                 &&showIconType.equals(detail.getIconType());
//                     }
//             ).findFirst();
//             if(optional.isPresent()){
//                 pv.setMainImg(optional.get().getIcon());
//                 pv.setMainImgNew(optional.get().getIcon());
//             }
//         }else{
//             //App渠道
//             //老版本app ICON
//             optional = detailList.stream().filter(
//                     detail->{
//                         return ShopCarTypeIconTypeEnums.ICON_OLD.getCode().equals(detail.getChannelType())
//                                 &&showIconType.equals(detail.getIconType());
//                     }
//             ).findFirst();
//             if(optional.isPresent()){
//                 pv.setMainImg(optional.get().getIcon());
//             }
//             //新版本app ICON
//             optional = detailList.stream().filter(
//                     detail->{
//                         return ShopCarTypeIconTypeEnums.ICON_NEW.getCode().equals(detail.getChannelType())
//                                 &&showIconType.equals(detail.getIconType());
//                     }
//             ).findFirst();
//             if(optional.isPresent()){
//                 pv.setMainImgNew(optional.get().getIcon());
//             }
//         }
//         return pv;
//     }
//     /**
//      * @Description: 将订单实体转换成OrderVo
//      * @Version 1.0  2018/8/31  9:57  by  王利涛(wanglt@cloud-young.com) 创建
//      * @param   order 订单实体
//      * @return
//      */
//     public static OrderVo convertOrderVO(Order order,Integer iconType,Integer iconShowType){
//         OrderVo ordervo = OrderObjectUtils.convertOrderVO(order,iconType, CarOrderIconVersionTypeEnums.ICON_OLD,iconShowType);
//         // 由于URL分割工具类在api项目配置，所以需要放到此处来处理url
//         for(OrderItemVo item : ordervo.getItemVos()){
//             item.setMainImg(SplicePathUtil.spliceUrl(item.getMainImg()));
//             item.setMainImgNew(SplicePathUtil.spliceUrl(item.getMainImgNew()));
//             item.setIconSnapshot(null);
//             item.setSnapshot(null);
//             ordervo.setTakeCode(item.getTakeCode());
//         }
//
//         return ordervo;
//     }
//
//	 /**
//	  * @Description: 通过订单实体和订单明细得到优惠券
//	  * @Version 1.0  2018/8/31  9:58  by  王利涛(wanglt@cloud-young.com) 创建
//	  * @param   order 订单实体 item 订单明细
//	  * @return
//	  */
//	public static CouponRecordParamter convertCouponFromOrder(Order order ,OrderItem item) {
//		String snapshot = item.getSnapshot();
//		if (StringUtils.isNotEmpty(snapshot)) {
//			OrderItemSnapshot itemsnapshot = JsonUtil.Json2Object(snapshot, OrderItemSnapshot.class);
//			String officialProm = itemsnapshot.getOfficialPromotionInfo();
//			if (StringUtils.isNotEmpty(officialProm)) {
//				CouponRecordParamter param = JsonUtil.Json2Object(officialProm, CouponRecordParamter.class);
//				param.setOrderCreationDate(order.getCreateTime());
//				param.setUsageTarget(order.getDealerCode());
//				param.setUseMobile(order.getBookMobile());
//				param.setUseUserName(order.getBookName());
//				param.setOrderItemId(item.getOrderItemId());
//				param.setOrderSn(order.getOrderSn());
//				return param;
//			}
//		}
//		return null;
//
//	}
//
//     /**
//      * @Description: 为用户绑定信息设置终端信息
//      * @Version 1.0  2018/8/31  9:59  by  王利涛(wanglt@cloud-young.com) 创建
//      * @param   op 订单创建输入参数 up 用户绑定信息输入参数
//      * @return
//      */
//	public static void processAccessChannel(CreateOrderParameter op, UserLoginBindingParameter up) {
//		if(up == null) {
//			return;
//		}
//		String channel = up.getAccessChannel();
//		if(ChannelInfoEnum.LLB_WX_PUBLIC.getChanneInfoId().toString().equals(channel)) {
//			op.setAccessChannel(OrderAccessChannelEnum.WX.getCode().toString());
//			return;
//		}
//
//		if(OrderAccessChannelEnum.IOS.getDesc().equalsIgnoreCase(up.getPlatformNo())) {
//			op.setAccessChannel(OrderAccessChannelEnum.IOS.getCode().toString());
//			return;
//		}
//		if(OrderAccessChannelEnum.ANDROID.getDesc().equalsIgnoreCase(up.getPlatformNo())) {
//			op.setAccessChannel(OrderAccessChannelEnum.ANDROID.getCode().toString());
//		}
//        //web商城渠道
//        if(ChannelInfoEnum.LLB_WEB_MALL.getChanneInfoId().toString().equals(channel)) {
//            op.setAccessChannel(OrderAccessChannelEnum.PC_WEB_MALL.getCode().toString());
//            return;
//        }
//	}
//
//	/**
//	 * @Description: 为订单输入参数设置下单渠道
//	 * @Version 1.0  2018-06-20  17:12  by  王利涛(wanglt@cloud-young.com) 创建
//	 * @param   op 订单输入参数 up 用户登录绑定信息
//	 * @return
//	 */
//	public static void processOrderChannel(EcOrderCreateParameter op, UserLoginBindingParameter up) {
//		if(up == null) {
//			return;
//		}
//		String channel = up.getAccessChannel();
//		if(ChannelInfoEnum.LLB_WX_PUBLIC.getChanneInfoId().toString().equals(channel)) {
//			op.setOrderChannel(OrderAccessChannelEnum.WX.getCode());
//			return;
//		}
//		if(OrderAccessChannelEnum.IOS.getDesc().equalsIgnoreCase(up.getPlatformNo())) {
//			op.setOrderChannel(OrderAccessChannelEnum.IOS.getCode());
//			return;
//		}
//		if(OrderAccessChannelEnum.ANDROID.getDesc().equalsIgnoreCase(up.getPlatformNo())) {
//			op.setOrderChannel(OrderAccessChannelEnum.ANDROID.getCode());
//		}
//        if(ChannelInfoEnum.LLB_MINIPROGRAM_MALL.getPlatform().equalsIgnoreCase(up.getPlatformNo())) {
//            op.setOrderChannel(OrderAccessChannelEnum.MINI_PROGRAM_MALL.getCode());
//            return;
//        }
//	}
//
//	/**
//	 * @Description: 将订单输入参数转换成EcOrderParamter 对象
//	 * @Version 1.0  2018-06-21  18:11  by  王利涛(wanglt@cloud-young.com) 创建
//	 * @param   parameter 订单输入参数
//	 * @return   返回 EcOrderParamter 对象
//	 */
//	public static EcOrderCommonParamter convertEcOrderCommonParamterFromParameter (EcOrderCreateParameter parameter){
//		EcOrderCommonParamter ecOrderParamter=new EcOrderCommonParamter();
//		ecOrderParamter.setOrderSn(parameter.getOrderSn());
//		ecOrderParamter.setUserId(parameter.getUserId());
//		List<com.llb.cloudyoung.shop.parameter.EcOrderCommodityParamter> orderCommoditys=parameter.getOrderCommoditys();
//		List<EcOrderCommodityCommonParamter> ecOrderCommodityParamters=orderCommoditys.stream().map(
//				ecOrderCommodityParameter->{
//					EcOrderCommodityCommonParamter ecCommodity=new EcOrderCommodityCommonParamter();
//					ecCommodity.setCommodityId(ecOrderCommodityParameter.getCommodityId());
//					ecCommodity.setCommoditySkuId(ecOrderCommodityParameter.getCommoditySkuId());
//					ecCommodity.setQuantity(ecOrderCommodityParameter.getQuantity());
//                    return ecCommodity;
//				}
//		).collect(Collectors.toList());
//		//得到订单过期
//		ecOrderParamter.setEcOrderCommodityCommonParamterList(ecOrderCommodityParamters);
//		return ecOrderParamter;
//	}
//
//	/**
//	 * @Description: 将订单输入参数转换成EcOrderParamter 对象
//	 * @Version 1.0  2018-06-21  18:11  by  王利涛(wanglt@cloud-young.com) 创建
//	 * @param   parameter 订单输入参数
//	 * @return   返回 EcOrderParamter 对象
//	 */
//	public static EcOrderParamter convertEcOrderParamterFromParameter (EcOrderCreateParameter parameter){
//		EcOrderParamter ecOrderParamter=new EcOrderParamter();
//		ecOrderParamter.setOrderSn(parameter.getOrderSn());
//		ecOrderParamter.setUserId(parameter.getUserId());
//        //设置经销商id
//        ecOrderParamter.setDealerId(parameter.getDealerId());
//        List<EcOrderCommodityInfoVo> ecOrderCommodityInfoVos=parameter.getEcOrderCommodityVos();
//        if(Objects.isNull(ecOrderCommodityInfoVos)){
//            ecOrderCommodityInfoVos=Lists.newArrayList();
//        }
//        //
//        //设置是否原价购买
//        Map<Long,EcOrderCommodityInfoVo> ecOrderCommodityInfoVoMap= ecOrderCommodityInfoVos
//                .stream().
//                collect(Collectors.toMap(EcOrderCommodityInfoVo::getCommoditySkuId, a -> a, (oldValue, newValue) -> oldValue));
//        List<EcOrderCommodityParamter> ecOrderCommodityParamters=parameter.getOrderCommoditys().stream().peek(
//                ecOrderCommodityParamter -> {
//                    EcOrderCommodityInfoVo ecOrderCommodityInfoVo = null;
//                    if (!ecOrderCommodityInfoVoMap.isEmpty()) {
//                        ecOrderCommodityInfoVo = ecOrderCommodityInfoVoMap.get(ecOrderCommodityParamter.getCommoditySkuId());
//                    }
//                    if (Objects.nonNull(ecOrderCommodityInfoVo)) {
//                        ecOrderCommodityParamter.setAllowOriginalPriceSell(ecOrderCommodityInfoVo.getAllowOriginalPriceSell());
//                    }
//                }
//        ).collect(Collectors.toList());
//		ecOrderParamter.setEcOrderCommodityParamters(ecOrderCommodityParamters);
//		return ecOrderParamter;
//	}
//	/**
//	 * @Description: 将订单商品信息转成订单商品快照
//	 * @Version 1.0  2018-06-21  18:50  by  王利涛(wanglt@cloud-young.com) 创建
//	 * @param   ecOrderCommodityInfoVos 订单商品信息
//	 * @return   返回订单商品快照
//	 */
//	public static EcOrderCheckVo getOrderCheckVoFromParm(List<EcOrderCommodityInfoVo> ecOrderCommodityInfoVos,
//                                                         List<EcOrderCouponParameter> ecOrderCouponParameters,
//                                                         EcOrder order){
//		EcOrderCheckVo ecOrderCheckVo=new EcOrderCheckVo();
//		//ecOrderCheckVo.setEcOrderCommodityVos(convertEcOrderCommodityVosFromParm(ecOrderCommodityInfoVos));
//        ecOrderCheckVo.setEcOrderCommodityVos(ecOrderCommodityInfoVos);
//		ecOrderCheckVo.setEcOrderCouponParameters(ecOrderCouponParameters);
//        ecOrderCheckVo.setOrder(order);
//		return ecOrderCheckVo;
//	}
//	/**
//	 * @Description: 将订单实体转成调用端需要的订单对象
//	 * @Version 1.0  2018-06-21  18:50  by  王利涛(wanglt@cloud-young.com) 创建
//	 * @param   order 订单实体
//	 * @return   返回下单后的订单对象
//	 */
//	public static CreateEcOrderVo convertCreateEcOrderVoFromParm(EcOrder order) {
//		CreateEcOrderVo orderVo=new CreateEcOrderVo();
//		orderVo.setOrderSn(order.getOrderSn());
//		orderVo.setTotalAmount(order.getTotalAmount());
//		orderVo.setPayAmount(order.getPayAmount());
//		orderVo.setAmount(order.getAmount());
//		//设置订单未支付过期秒数
//		if(Objects.nonNull(order.getEcOrderExpired())){orderVo.setOrderExpiredSeconds(order.getEcOrderExpired().getExpireSeconds());}
//		orderVo.setOrderCreateDate(order.getSubmitTime());
//		try {
//			String temp=EncryptUtil.base64Encode(order.getCreateUserId().toString());
//			orderVo.setCreateUserId(temp);
//		} catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
//		orderVo.setOrderId(order.getOrderId());
//		orderVo.setSignForPay(OrderPaySignUtil.signForPay(order));
//		return orderVo;
//	}
//	/**
//	 * @Description: 根据订单输入参数返回订单和优惠券关系实体
//	 * @Version 1.0  2018-06-22  16:01  by  王利涛(wanglt@cloud-young.com) 创建
//	 * @param   parameter 订单输入参数
//	 * @return   返回订单和优惠券关系实体
//	 */
//	public static List<EcOrderCouponParameter> convertOrderCouponParameter(EcOrderCreateParameter parameter){
//        List<EcOrderCouponVo> ecOrderCouponVos = parameter.getEcOrderCouponVos();
//        if (CollectionUtils.isEmpty(ecOrderCouponVos)) return null;
//        return ecOrderCouponVos.stream().map(
//                ecOrderCouponVo -> {
//                    EcOrderCouponParameter orderCoupon = new EcOrderCouponParameter();
//                    orderCoupon.setOrderSn(parameter.getOrderSn());
//                    orderCoupon.setCouponId(ecOrderCouponVo.getCouponId());
//                    orderCoupon.setCouponDisplayName(ecOrderCouponVo.getAppCouponName() + ecOrderCouponVo.getCouponAmount() + "");
//                    orderCoupon.setCouponAmount(ecOrderCouponVo.getCouponAmount());
//                    orderCoupon.setCouponCode(ecOrderCouponVo.getCouponCode());
//                    //设置优惠券快照
//                    orderCoupon.setSnapshot(JsonUtil.Object2Json(ecOrderCouponVo));
//                    orderCoupon.setCouponName(ecOrderCouponVo.getAppCouponName());
//                    orderCoupon.setCouponCode(ecOrderCouponVo.getCouponCode());
//                    return orderCoupon;
//                }
//        ).collect(Collectors.toList());
//    }
//
//    /**
//     * @Description: 将订单输入参数转换成EcOrder 对象
//     * @Version 1.0  2018-06-20  20:23  by  王利涛(wanglt@cloud-young.com) 创建
//     * @param   parameter
//     * @return   返回EcOrder对象
//     */
//    public static EcOrder convertOrderFromParameter(EcOrderCreateParameter parameter,
//                                                    DealerUserInfoVo dealerUserInfoVo,
//                                                    EcOrder order){
//
//        //设置订单号
//        order.setOrderSn(parameter.getOrderSn());
//        //设置下单渠道
//        order.setOrderChannel(parameter.getOrderChannel());
//
//        order.setSubmitTime(parameter.getSubmitDate());
//        order.setCreateUserId(parameter.getUserId());
//
//        order.setCreateDate(parameter.getSubmitDate());
//        order.setRemark(parameter.getRemark());
//        order.setSubmitTime(parameter.getSubmitDate());
//        order.setDealerId(parameter.getDealerId());
//        order.setSubmitUserId(parameter.getUserId());
//        order.setDeliveryMethod(ZeroOrOneEnum.ZERO.getCode());
//        order.setDeviceType(parameter.getDeviceType());
//        order.setReceiverAddress(parameter.getReceiverAddress());
//        order.setReceiverAreaCode(parameter.getReceiverAreaCode());
//        order.setReceiverAreaAddress(parameter.getReceiverAreaAddress());
//        order.setReceiverMobile(parameter.getReceiverMobile());
//        order.setSubmitUserMobile(parameter.getSubmitUserMobile());
//        order.setRecommendDealerCode(parameter.getRecommendDealerCode());
//        order.setReceiverName(parameter.getReceiverName());
//        order.setShowFlag(true);
//        order.setTerminalInfo(parameter.getTerminalInfo());
//
//
//        //增加是否推荐购买标志
//        order.setRecommendBuyFlag(Objects.nonNull(parameter.getRecommenderUserId())?ZeroOrOneEnum.ONE.getCode():ZeroOrOneEnum.ZERO.getCode());
//        //增加下单人用户身份
//        order.setSubmitUserRank(Objects.nonNull(parameter.getDealerId())? EcOrderSubmitUserRankEnum.DEALER.getCode(): EcOrderSubmitUserRankEnum.NORMAL.getCode());
//        //设置订单商品数量
//        List<EcOrderCommodityParamter> orderCommoditys=parameter.getOrderCommoditys();
//        Integer totalQuantity=orderCommoditys.stream().mapToInt(com.llb.cloudyoung.shop.parameter.EcOrderCommodityParamter::getQuantity).sum();
//        order.setCommodityQuantity(totalQuantity);
//        //增加活动订单标志
//        Boolean activityFlag=orderCommoditys.stream().anyMatch(
//                ecOrderCommodityParamter->{
//                    return ecOrderCommodityParamter.getCommodityActivityFlag();
//                }
//        );
//        order.setActivityFlag(activityFlag?ZeroOrOneEnum.ONE.getCode():ZeroOrOneEnum.ZERO.getCode());
//        //
//        List<EcOrderDetail> ecOrderDetails=order.getEcOrderDetailList().stream().peek(
//                detail->{
//                    detail.setOrderSn(order.getOrderSn());
//                }
//        ).collect(Collectors.toList());
//        order.setEcOrderDetailList(ecOrderDetails);
//
//        Map<Long,List<EcOrderDetail>> supperIdMap=order.getEcOrderDetailList().stream().collect(Collectors.groupingBy(EcOrderDetail::getSupplierId));
//        if(Objects.nonNull(supperIdMap)&&supperIdMap.keySet().size()==1){
//            //所有商品都属于一个供应商
//            order.setSupplierId(supperIdMap.keySet().stream().findFirst().get());
//        }
//        //设置订单优惠券关系
//        order.setEcOrderCouponParameters(parameter.getEcOrderCouponParameters());
//        //设置订单过期记录
//        order.setEcOrderExpired(convertOrderExpired(parameter));
//        order.setOriginalOrderSn(order.getOrderSn());
//        //封装推荐购买记录实体
//        order.setEcOrderRecommendBuy(buildEcOrderRecommendBuy(order,dealerUserInfoVo));
//        return order;
//    }
//
//    private static EcOrderRecommendBuy buildEcOrderRecommendBuy(EcOrder order,DealerUserInfoVo dealerUserInfoVo){
//        if(Objects.isNull(order.getRecommenderUserId())){
//            return null;
//        }
//        //判断下单人和推荐人是否是同一人
//        if(order.getCreateUserId().equals(order.getRecommenderUserId())){
//            return null;
//        }
//        //end by
//        EcOrderRecommendBuy ecOrderRecommendBuy=new EcOrderRecommendBuy();
//        ecOrderRecommendBuy.setCreateUserId(order.getCreateUserId());
//        ecOrderRecommendBuy.setOrderSn(order.getOrderSn());
//        ecOrderRecommendBuy.setRecommenderId(order.getRecommenderId());
//        ecOrderRecommendBuy.setRecommenderUserId(order.getRecommenderUserId());
//        ecOrderRecommendBuy.setOrderSubmitUser(order.getCreateUserId());
//        ecOrderRecommendBuy.setOrderTotalAmount(order.getTotalAmount());
//        ecOrderRecommendBuy.setOrderAmount(order.getAmount());
//        ecOrderRecommendBuy.setOrderReceiverName(order.getReceiverName());
//        ecOrderRecommendBuy.setOrderSubmitTime(order.getSubmitTime());
//        ecOrderRecommendBuy.setOriginalOrderSn(order.getOrderSn());
//        //获取推荐人经销商信息
//        if(Objects.nonNull(dealerUserInfoVo)){
//            ecOrderRecommendBuy.setRecommenderDealerId(dealerUserInfoVo.getDealerId());
//            ecOrderRecommendBuy.setRecommenderUserName(dealerUserInfoVo.getClerkName());
//            ecOrderRecommendBuy.setRecommenderMobile(dealerUserInfoVo.getClerkMobile());
//            ecOrderRecommendBuy.setRecommenderDealerName(dealerUserInfoVo.getDealerName());
//            ecOrderRecommendBuy.setRecommenderDealerCode(dealerUserInfoVo.getDealerCode());
//            ecOrderRecommendBuy.setRecommenderDealerServiceCode(dealerUserInfoVo.getServiceCode());
//        }
//        return ecOrderRecommendBuy;
//    }
//
//    public static  List<EcOrderDetail> getGroupActivityEcOrderDetailLs(EcGroupAcitvityCreateParameter orderParameter){
//        List<com.llb.cloudyoung.shop.parameter.EcOrderCommodityParamter> orderCommoditys=orderParameter.getOrderCommoditys();
//        List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo> ecOrderCommodityVos=orderParameter.getEcOrderCommodityVos();
//        Map<Long,List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo>> ecOrderMap=
//                ecOrderCommodityVos.stream().collect(Collectors.groupingBy(com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo::getCommoditySkuId));
//        Long deaId=orderParameter.getDealerId();
//
//        return orderCommoditys.stream().map(
//                ecOrderCommodityParameter -> {
//                    EcOrderDetail detail = new EcOrderDetail();
//                    //设置商品ID
//                    detail.setCommoditySkuId(ecOrderCommodityParameter.getCommoditySkuId());
//                    detail.setCommodityId(ecOrderCommodityParameter.getCommodityId());
//                    detail.setOrderSn(orderParameter.getOrderSn());
//                    detail.setBuyQuantity(ecOrderCommodityParameter.getQuantity());
//                    detail.setCreateUserId(orderParameter.getUserId());
//                    detail.setPayTime(null);
//
//                    detail.setCommodityActivityId(orderParameter.getGroupActivityId());
//                    detail.setActivityDetailId(orderParameter.getGroupActivityDetailId());
//                    //
//                    List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo> ls = ecOrderMap.get(ecOrderCommodityParameter.getCommoditySkuId());
//                    if (!CollectionUtils.isEmpty(ls)) {
//                        com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo ecOrderCommodityVo = ls.get(0);
//                        //是否允许开发票
//                        detail.setAllowMakeInvoice(ZeroOrOneEnum.ONE.getCode().equals(ecOrderCommodityVo.getAllowMakeInvoice()));
//                        detail.setSupplierId(ecOrderCommodityVo.getSupplierId());
//                        detail.setCommodityName(ecOrderCommodityVo.getCommodityName());
//                        detail.setCommoditySkuSn(ecOrderCommodityVo.getSkuSn());
//                        //设置商品所属
//                        detail.setCommodityAscription(ecOrderCommodityVo.getCommodityAscription());
//                        //设置商品成本价
//                        if (Objects.nonNull(deaId) && deaId > 0) {
//                            detail.setPrimePrice(ecOrderCommodityVo.getSkuAgentPrimePrice());
//                        } else {
//                            detail.setPrimePrice(ecOrderCommodityVo.getSkuCommonPrimePrice());
//                        }
//
//                        detail.setOriginalPrice(ecOrderCommodityParameter.getSkuPrice());
//                        detail.setDealerId(deaId);
//                        detail.setPrice(ecOrderCommodityParameter.getSkuPrice());
//
//
//                        detail.setTotalAmount(detail.getOriginalPrice().multiply(BigDecimal.valueOf(detail.getBuyQuantity())));
//                        if (orderCommoditys.size() == 1) {
//                            detail.setPayAmount(orderParameter.getPayAmount());
//                            detail.setAmount(orderParameter.getPayAmount());
//                            detail.setDiscountAmount(orderParameter.getDiscountAmount());
//                            detail.setOrderDiscountAmount(orderParameter.getOrderDiscountAmount());
//                            detail.setCommodityDiscountAmount(orderParameter.getCommodityDiscountAmount());
//                        } else {
//                            detail.setPayAmount(detail.getTotalAmount());
//                            detail.setAmount(detail.getTotalAmount());
//                            detail.setDiscountAmount(BigDecimal.ZERO);
//                        }
//                        detail.setAllowSalesReturn(ZeroOrOneEnum.ONE.getCode().equals(ecOrderCommodityVo.getAllowSalesReturn()));
//                        detail.setSnapshot(JsonUtil.Object2Json(ecOrderCommodityVo));
//                    }
//                    return detail;
//                }
//        ).collect(Collectors.toList());
//    }
//    /**
//     * @Description: 将订单输入参数转换成EcOrderDetail对象
//     * @Version 1.0  2018-06-20  20:45  by  王利涛(wanglt@cloud-young.com) 创建
//     * @param   parameter 订单输入参数
//     * @return  返回EcOrderDetail对象
//     */
//    public static List<EcOrderDetail> convertOrderDetailFromParameter(EcOrderCreateParameter parameter){
//
//        List<com.llb.cloudyoung.shop.parameter.EcOrderCommodityParamter> orderCommoditys=parameter.getOrderCommoditys();
//        List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo> ecOrderCommodityVos=parameter.getEcOrderCommodityVos();
//        Map<Long,List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo>> ecOrderMap=
//                ecOrderCommodityVos.stream().collect(Collectors.groupingBy(com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo::getCommoditySkuId));
//        Long deaId=parameter.getDealerId();
//        List<EcOrderCouponParameter> ecOrderCouponParameters= parameter.getEcOrderCouponParameters();
//
//         if(CollectionUtils.isEmpty(ecOrderCouponParameters)){
//             ecOrderCouponParameters=Lists.newArrayList();
//         }
//
//        Map<Long,Long> ecOrderCouponParameterMap=ecOrderCouponParameters.stream().collect(Collectors.toMap(
//                EcOrderCouponParameter::getCommodityId,EcOrderCouponParameter::getCouponId
//        ));
//        return orderCommoditys.stream().map(
//                ecOrderCommodityParameter -> {
//                    EcOrderDetail detail = new EcOrderDetail();
//                    //设置商品ID
//                    detail.setCommoditySkuId(ecOrderCommodityParameter.getCommoditySkuId());
//                    detail.setCommodityId(ecOrderCommodityParameter.getCommodityId());
//                    detail.setOrderSn(parameter.getOrderSn());
//                    detail.setBuyQuantity(ecOrderCommodityParameter.getQuantity());
//                    detail.setCreateUserId(parameter.getUserId());
//                    detail.setPayTime(null);
//                    //订单明细关联的商品券code
//                    detail.setCouponCode(Objects.isNull(ecOrderCouponParameterMap.get(ecOrderCommodityParameter.getCommodityId())) ? null :
//                            ecOrderCouponParameterMap.get(ecOrderCommodityParameter.getCommodityId()).toString());
//                    //设置活动id
//                    if (ecOrderCommodityParameter.getCommodityActivityFlag()) {
//                        detail.setCommodityActivityId(ecOrderCommodityParameter.getCommodityActivityId());
//                    }
//                    //
//                    List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo> ls = ecOrderMap.get(ecOrderCommodityParameter.getCommoditySkuId());
//                    if (!CollectionUtils.isEmpty(ls)) {
//                        com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo ecOrderCommodityVo = ls.get(0);
//                        //是否允许开发票
//                        detail.setAllowMakeInvoice(ZeroOrOneEnum.ONE.getCode().equals(ecOrderCommodityVo.getAllowMakeInvoice()));
//                        detail.setSupplierId(ecOrderCommodityVo.getSupplierId());
//                        detail.setCommodityName(ecOrderCommodityVo.getCommodityName());
//                        detail.setCommoditySkuSn(ecOrderCommodityVo.getSkuSn());
//                        //设置商品所属
//                        detail.setCommodityAscription(ecOrderCommodityVo.getCommodityAscription());
//                        //设置商品成本价
//                        if (Objects.nonNull(deaId) && deaId > 0) {
//                            detail.setPrimePrice(ecOrderCommodityVo.getSkuAgentPrimePrice());
//                        } else {
//                            detail.setPrimePrice(ecOrderCommodityVo.getSkuCommonPrimePrice());
//                        }
//                        //判断活动商品标识
//                        if (ecOrderCommodityParameter.getCommodityActivityFlag()) {
//                            //活动商品
//                            if (Objects.isNull(deaId) || deaId < 1) {
//                                detail.setOriginalPrice(ecOrderCommodityVo.getCommonActivityPrice());
//                            } else {
//                                detail.setOriginalPrice(ecOrderCommodityVo.getDealerActivityPrice());
//                                detail.setDealerId(deaId);
//                            }
//                        } else {
//                            //非活动商品
//                            if (Objects.isNull(deaId) || deaId < 1) {
//                                detail.setOriginalPrice(ecOrderCommodityVo.getSkuPrice());
//                            } else {
//                                detail.setOriginalPrice(ecOrderCommodityVo.getSkuAgentPrice());
//                                detail.setDealerId(deaId);
//                            }
//                        }
//                        detail.setPrice(detail.getOriginalPrice());
//                        detail.setTotalAmount(detail.getOriginalPrice().multiply(BigDecimal.valueOf(detail.getBuyQuantity())));
//                        if (orderCommoditys.size() == 1) {
//                            detail.setPayAmount(parameter.getPayAmount());
//                            detail.setAmount(parameter.getPayAmount());
//                            detail.setDiscountAmount(parameter.getDiscountAmount());
//                            detail.setOrderDiscountAmount(parameter.getOrderDiscountAmount());
//                            detail.setCommodityDiscountAmount(parameter.getCommodityDiscountAmount());
//                        } else {
//                            detail.setPayAmount(detail.getTotalAmount());
//                            detail.setAmount(detail.getTotalAmount());
//                            detail.setDiscountAmount(BigDecimal.ZERO);
//                        }
//                        detail.setAllowSalesReturn(ZeroOrOneEnum.ONE.getCode().equals(ecOrderCommodityVo.getAllowSalesReturn()));
//                        detail.setSnapshot(JsonUtil.Object2Json(ecOrderCommodityVo));
//                    }
//                    return detail;
//                }
//        ).collect(Collectors.toList());
//    }
//
//    /**
//     * @Description: 根据订单输入参数返回过期订单实体
//     * @Version 1.0  2018-06-22  16:01  by  王利涛(wanglt@cloud-young.com) 创建
//     * @param   parameter 订单输入参数
//     * @return   返回过期订单实体
//     */
//    public static EcOrderExpired convertOrderExpired(EcOrderCreateParameter parameter){
//        List<com.llb.cloudyoung.shop.vo.EcOrderCommodityInfoVo> ecOrderCommodityVos=parameter.getEcOrderCommodityVos();
//        if(CollectionUtils.isEmpty(ecOrderCommodityVos)) return null;
//        Integer senconds=ecOrderCommodityVos.stream().map(ecOrderCommodityVo->{
//            return Objects.isNull(ecOrderCommodityVo.getCommodityPayOvertime())?minAwaitPaySeconds:ecOrderCommodityVo.getCommodityPayOvertime();
//        }).min((Integer o1,Integer o2)->{
//            return o1.compareTo(o2);
//        }).get();
//        EcOrderExpired ecOrderExpired=new EcOrderExpired();
//        ecOrderExpired.setOrderSn(parameter.getOrderSn());
//        ecOrderExpired.setExpireType(EcOrderExpireTypeEnum.AWAIT_PAY.getCode());
//        ecOrderExpired.setCreateUserId(parameter.getUserId());
//        ecOrderExpired.setSubmitTime(parameter.getSubmitDate());
//        ecOrderExpired.setExpireSeconds(senconds);
//        ecOrderExpired.setExpireTime(DateUtils.addSeconds(parameter.getSubmitDate(),senconds));
//        return ecOrderExpired;
//    }
//
//    /**
//     * @Description: 转换得到订单中的整车车型ICON图片集合
//     * @Version 1.0  2018/12/18  14:42  by  王利涛(wanglt@cloud-young.com) 创建
//     * @param   orderCarImageVos 商品中的整车车型ICON 集合类
//     * @return  返回 订单中的整车车型ICON图片集合
//     */
//    public static List<CarTypeIconVo> convertCarTypeIconVo(List<OrderCarImageVo> orderCarImageVos){
//        List<CarTypeIconVo> list=Lists.newArrayList();
//
//        if(org.apache.commons.collections.CollectionUtils.isEmpty(orderCarImageVos)){
//            return list;
//        }
//        return orderCarImageVos.stream().map(
//                detail -> {
//                    CarTypeIconVo vo=new CarTypeIconVo();
//                    vo.setChannelType(detail.getChannelType());
//                    vo.setIconType(detail.getIconType());
//                    vo.setIcon(detail.getIcon());
//                    return vo;
//                }
//        ).collect(Collectors.toList());
//    }
//}
